import Vue from "vue";

import Vuex from "vuex";

Vue.use(Vuex);

//菜
let state = {
	sum: 1, //测试
	identity: uni.getStorageSync('identity') || '', //当前角色
	identity_staff_id: uni.getStorageSync('identity_staff_id') || '', //如果是store
	permission: '',
}

//服务员
let actions = {
	chooseRole(context, item) {
		if (item.identity == 'store') {
			context.state.identity = item.identity
			context.state.identity_staff_id = ''
		} else if (item.identity == 'staff') {
			context.state.identity = item.identity
			context.state.identity_staff_id = item.staff_id
		}
		uni.setStorageSync('identity', context.state.identity)
		uni.setStorageSync('identity_staff_id', context.state.identity_staff_id)
	},
	clearState(context) {
		console.log('清空');
		uni.removeStorageSync('identity')
		uni.removeStorageSync('identity_staff_id')
		context.state.identity = ''
		context.state.identity_staff_id = ''
		context.state.permission = ''
	}
}

//厨师
let mutations = {

}

let getters = {
	bigSum(state) {
		return state.sum * 2
	},
}

export default new Vuex.Store({
	actions,
	mutations,
	state,
	getters
})